/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.scalia.meteocal.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author gabriele
 */
@Entity(name = "NOTIFICATION")
@NamedQueries({
        @NamedQuery(name = Notification.findAllOfUser, query = "SELECT n FROM NOTIFICATION n WHERE n.user = :user"),
        @NamedQuery(name = Notification.findAllOfUserNewFirst, query = "SELECT n FROM NOTIFICATION n WHERE n.user = :user ORDER BY n.creationTimestamp DESC"),
        @NamedQuery(name = Notification.findAllOfEvent, query = "SELECT n FROM NOTIFICATION n WHERE n.event = :event")
})
public class Notification implements Serializable {
    
    public static final String findAllOfUser = "findAllNotificationsOfUser";
    public static final String findAllOfUserNewFirst = "findAllNotificationsOfUserNewFirst";
    public static final String findAllOfEvent = "findAllNotificationsOfEvent";
    
    protected Notification() {
        
    }

    public Notification(NotificationType notificationType, User user, Event event, Date creationTimestamp) {
        this.notificationType = notificationType;
        this.user = user;
        this.event = event;
        this.creationTimestamp = creationTimestamp;
        alreadyRead = false;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @NotNull(message = Messages.NOT_EMPTY)
    private NotificationType notificationType;
    
    private User user;
    
    private Event event;
    
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull(message = Messages.NOT_EMPTY)
    private Date creationTimestamp;
    
    @NotNull(message = Messages.NOT_EMPTY)
    private boolean alreadyRead;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public NotificationType getNotificationType() {
        return notificationType;
    }

    public void setNotificationType(NotificationType notificationType) {
        this.notificationType = notificationType;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public Date getCreationTimestamp() {
        return creationTimestamp;
    }

    public void setCreationTimestamp(Date creationTimestamp) {
        this.creationTimestamp = creationTimestamp;
    }

    public boolean getRead() {
        return alreadyRead;
    }

    public void setRead(boolean read) {
        this.alreadyRead = read;
    }
}
